import { useUserStore } from "@/stores/user";

const TOKEN_KEY = 'Authorization';

export function getToken() {
  return localStorage.getItem(TOKEN_KEY);
}

export function setToken(token: string) {
  return localStorage.setItem(TOKEN_KEY, token)
}

export function removeToken() {
  return localStorage.removeItem(TOKEN_KEY);
}

export function hasPermission(permission: string | string[]) {
  const { authoritys } = useUserStore();
  if(Array.isArray(permission)) {
   return permission.every(item => {
      return authoritys.includes(item);
    });
  }else {
    if(authoritys.includes(permission)) {
      return true;
    }
  }
}